<?php include "include/function_library.php"; ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "html/header.html"; ?>

</head>
<body class="tcuk home">

	<div id="wp">
	
		<?php  include "html/menu.html"; ?>
		
		<!-- CONTENT STARTS-->
		<div id="ct">
			<?php if(get("deleted") == "1") echo "<div class='alert success'>Transportation Deleted Successfully!</div>";	?>
			
			<div id="query_area">
				<!--  Query Area Html Part -->
				<fieldset>
				<legend>&nbsp;&nbsp;Filter results:</legend>
				<form action="<?php echo curPageURL(); ?>" method="post">
					<input type="text" name="q_source" id="q_source" placeholder="Source" />
					
					<input type="text" name="q_destination" id="q_destination" placeholder="Destination" />
					
					<input type="text" name="q_price" id="q_price" placeholder="Price" />
					
					<select name="q_type" id="q_type">
						<option value="All">Transportation Type</option>
						<option value="Bus">Bus</option>
						<option value="Plane">Plane</option>
						<option value="Ship">Ship</option>
						<option value="Train">Train</option>
					</select>
					
					<input type="submit" name="q_search" id="q_search" value="Search"/>
				</form>
				</fieldset>
				<?php 
					/* Query Area Php Part */
					$query = "SELECT * FROM transportation";
					
					if(post("q_search")) {
						$q_source = post("q_source");
						$q_destination = post("q_destination");
						$q_price = post("q_price");
						$q_type = post("q_type");
						
						$query .= " WHERE id > 0 ";
						if($q_source != "") $query .= "AND source LIKE '%$q_source%' ";
						if($q_destination != "") $query .= "AND destination LIKE '%$q_destination%' ";
						if($q_price != "") $query .= "AND price = '$q_price' ";
						if($q_type != "" && $q_type != "All") $query .= "AND type = '$q_type' ";
					}
				?>
			</div>
		
			<table border="" style="margin-top: 0px;">
			<thead>
				<tr>
					<th>Transportation</th>
					<th>Date</th>
					<th>Price</th>
					<th>Type</th>
					<th>Capacity</th>
				</tr>
			</thead>
			<tbody>
				<?php 
					$result = sql_query($query);
					while($tuple = mysql_fetch_assoc($result)) {
						?>
						<tr>
							<td><a href="transportation_detail.php?id=<?php echo $tuple["id"]; ?>"><?php echo $tuple["source"]; ?> - <?php echo $tuple["destination"]; ?></a></td>
							<td><?php echo $tuple["date"]; ?></td>
							<td><?php echo $tuple["price"]; ?></td>
							<td><?php echo $tuple["type"]; ?></td>
							<td><?php echo $tuple["capacity"]; ?></td>
						</tr>
						<?php
					}
				?>
			</tbody>
			</table>
		
		</div> 	
		<!-- CONTENT ENDS-->		
		
		<?php include "html/footer.html"; ?>
		
	</div>
	
</body>
</html>